﻿using System;

namespace ConsoleLearn
{

    //Person对象
    public class Person
    {
        /*public Person()
        {
            Console.WriteLine("Person的无参构造方法!");
        }*/

        public Person(string name, int age)
        {
            this.Age = age;
            this.Name = name;
            Console.WriteLine("Person的有参构造方法!");
        }

        //字段
        public string desc = "这是一个人类!";
        //属性
        public string Name {set;get;}
        //简写的属性的get和set
        public int Age { set; get; }

        public void say()
        {
            Console.WriteLine("我是人类Person的say()方法");
        }

        virtual public void show()
        {
            Console.WriteLine("Person:[Name:{0},Age{1}]", this.Name, this.Age);
        }

    }

    public class Chinese : Person
    {

        //子类默认覆盖父类的同名属性,加上new关键字显示指明
        public new string Name { get; set; }
        public new int Age { get; set; }

        public Chinese() : base("Bart2",16) { Console.WriteLine("Chinese的无参构造方法!"); }

        public Chinese(string name, int age) :base(name,age)
        {            
            this.Age = age;
            this.Name = name;
            Console.WriteLine("Chinese的有参构造方法!");
        }

        public new void say()
        {
            Console.WriteLine("我是中国人Chinese的say()方法");
        }

        //override 表示重写了父类的对应方法,但是父类的该方法必须被virtual,abstract,override 修饰
        override public void show()
        {
            Console.WriteLine("Chinese:[Name:{0},Age{1}]",Name,Age);
        }

    }

    class MultiState
    {
        public static void Main(string[] args)
        {
            //Person p = new Person("Bart", 15);
            //p.say();
            //p.show();
            Chinese c = new Chinese("Bart",15);
            c.say();
            c.show();
            Console.ReadKey();

        } 
    }
}
